/**
 * exec 函数族
*/

#include <stdio.h>
#include <stdlib.h>

#include <unistd.h>

int main()
{

    pid_t pid;
    pid = fork();
    if (0 > pid)
    {
        perror("fork error: ");
        exit(EXIT_FAILURE);
    }
    else if (0 == pid)
    {
        printf("\nexecl :\n");
        execl("/bin/ls", "-a", NULL);
    }
    sleep(2);

    pid = fork();
    if (0 > pid)
    {
        perror("fork error: ");
        exit(EXIT_FAILURE);
    }
    else if (0 == pid)
    {
        printf("\nexecv :\n");
        char *argv[] = {"-a"};
        execv("/bin/ls", argv);
    }
    sleep(2);

    pid = fork();
    if (0 > pid)
    {
        perror("fork error: ");
        exit(EXIT_FAILURE);
    }
    else if (0 == pid)
    {
        printf("\nexecle :\n");
        execle("/bin/ls", "-a", NULL, NULL);
    }
    sleep(2);

    pid = fork();
    if (0 > pid)
    {
        perror("fork error: ");
        exit(EXIT_FAILURE);
    }
    else if (0 == pid)
    {
        printf("\nexecve :\n");
        char *argv[] = {"-a"};
        execve("/bin/ls", argv,NULL);
    }
    sleep(2);

    pid = fork();
    if (0 > pid)
    {
        perror("fork error: ");
        exit(EXIT_FAILURE);
    }
    else if (0 == pid)
    {
        printf("\nexeclp :\n");
        execlp("ls", "-a", NULL);
    }
    sleep(2);


    pid = fork();
    if (0 > pid)
    {
        perror("fork error: ");
        exit(EXIT_FAILURE);
    }
    else if (0 == pid)
    {
        printf("\nexecvp :\n");
        char *argv[] = {"-a"};
        execvp("ls", argv);
    }
    sleep(2);

    return 0;
}